﻿// 项目：	Guan.CMS.Web.Core - Guan.CMS
// 文件名：	CmsUser.cs
// 
// 修改时间：2013-03-06 19:27
// 修改人：	Cooclsee

using System;
using System.Security.Principal;
using System.Web.Security;

namespace Guan.CMS.Web.Core.Models
{
    [Serializable]
    public class CmsUser : IIdentity
    {
        public CmsUser()
        {
        }

        public CmsUser(string name, string displayName, int userId)
        {
            this.Name = name;
            this.DisplayName = displayName;
            this.UserId = userId;
        }

        public CmsUser(string name, string displayName, int userId, string roleName)
        {
            this.Name = name;
            this.DisplayName = displayName;
            this.UserId = userId;
            this.RoleName = roleName;
        }

        public CmsUser(string name, UserInfo userInfo)
            : this(name, userInfo.DisplayName, userInfo.UserId, userInfo.RoleName)
        {
            if (userInfo == null)
            {
                throw new ArgumentNullException("userInfo");
            }
            this.UserId = userInfo.UserId;
        }

        public CmsUser(FormsAuthenticationTicket ticket) : this(ticket.Name, UserInfo.FromString(ticket.UserData))
        {
            if (ticket == null)
            {
                throw new ArgumentNullException("ticket");
            }
        }

        public string Name { get; private set; }

        public string AuthenticationType
        {
            get { return "CmsForms"; }
        }

        public bool IsAuthenticated
        {
            get { return true; }
        }

        public string DisplayName { get; private set; }
        public string RoleName { get; private set; }
        public int UserId { get; private set; }
    }
}